package org.example.seckill.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.example.seckill.config.RabbitMqConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author woopsion
 * @date 2025-07-05
 * 消息发送者 生产者
 */
@Service
@Slf4j
public class MQSender {

    //装配rabbitTemplate 很重要 操作rabbit的工具
    @Autowired
    private RabbitTemplate rabbitTemplate;
    
    public void send(Object msg){
        log.info("发送消息 ====== > " + msg);
        rabbitTemplate.convertAndSend("queue",msg);
    }    
    
    public void send_fanout(Object msg){
        log.info("发送消息 ====== > " + msg);
        rabbitTemplate.convertAndSend("exchange-fanout","",msg);
    }
    
    public void send_direct_pay(Object msg){
        rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_DIRECT, "pay",msg);
        log.info("pay发送消息 ====== > " + msg);
    }    
    
    public void send_direct_order(Object msg){
        rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_DIRECT, "order",msg);
        log.info("order发送消息 ====== > " + msg);
    }
}
